home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77688_log_view.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  4.4 KB  |  134 lines

  1. <%@ Language=VBScript   %>
  2. <% Option Explicit        %>
  3. <%
  4.     '-------------------------------------------------------------------------
  5.     ' log_view.asp: to view the log file through the iframe
  6.     '
  7.     ' NOTE: This is a customized page written to take care of the "Viewing"
  8.     ' of the log(text) files in the IFrame. 
  9.     ' This is not the types of the pages(area, property, etc) of the framework.
  10.     ' Hence, the events applicable to those is not used  here.
  11.     '
  12.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  13.     '-------------------------------------------------------------------------
  14. %>
  15.     <meta http-equiv="Content-Type" content="text/html; charset=<%=GetCharSet()%>">
  16.     <!-- #include virtual="/admin/inc_framework.asp" --> 
  17.     <!-- #include file="loc_Log.asp" -->
  18. <%
  19.     Dim G_FileToView    ' the file be displayed in the IFrame
  20.     Dim strFileError    ' to capture any file related error that occurs
  21.  
  22.     ' Get the File to be displayed through the Query String
  23.     G_FileToView = Request.QueryString("FileToView") 
  24.     If Len(Trim(G_FileToView)) <=0 Then
  25.         ' error occuerd. Display message and end response
  26.         Call ShowErrorMessageAndExit(L_NOLOGSAVAILABLE_TEXT)
  27.     End If
  28.     
  29.     ' Call the function to display the file contents.
  30.     ' The function returns "" <empty> string if no error occurs
  31.     ' In case of error, the error message is returned
  32.     strFileError = WriteFileData(G_FileToView)
  33.  
  34.     If ((Err.number <> 0) OR (Len(Trim(strFileError)) > 0 ))Then
  35.         ' error occuerd. Display message and end response
  36.         Call ShowErrorMessageAndExit(strFileError)
  37.     End If
  38.  
  39.     '-------------------------------------------------------------------------
  40.     ' Function name:    WriteFileData
  41.     ' Description:        Serves in Writing the file content
  42.     ' Input Variables:    strFilePath
  43.     ' Output Variables:    None
  44.     ' Returns:            Empty string if success, Error Message in case of any error
  45.     'Writes the log file content in the IFrame 
  46.     '-------------------------------------------------------------------------
  47.      Function WriteFileData(strFilePath)
  48.         On Error Resume Next
  49.         Err.Clear
  50.  
  51.         Dim objFso        ' the file system object
  52.         Dim objFile       ' the File object
  53.         Dim strFileData   ' the file data 
  54.  
  55.         Dim oEncoder
  56.         Set oEncoder = new CSAEncoder
  57.         
  58.         ' create the FSO
  59.         Set objFso = CreateObject("Scripting.FileSystemObject")
  60.         If Err.number <> 0 Then
  61.             WriteFileData = L_FSO_OBJECTCREATE_ERRORMESSAGE
  62.             Call SA_TraceOut(SA_GetScriptFileName(), "CreateObject(Scripting.FileSystemObject) error: " & Hex(Err.Numer) & " " & Err.Description)
  63.             Err.Clear 
  64.             Exit Function
  65.         End If
  66.  
  67.         'checking for the file existence
  68.         If  NOT (objFso.FileExists(strFilePath)) Then
  69.             ' file does not exist
  70.             WriteFileData = L_NOLOGSAVAILABLE_TEXT 
  71.             Call SA_TraceOut(SA_GetScriptFileName(), "File " & strFilePath & " does not exist.")
  72.             Err.Clear 
  73.             Exit Function
  74.         End IF 
  75.  
  76.         ' open the file
  77.         Set objFile=objFso.OpenTextFile(strFilePath)
  78.         If Err.number <> 0 Then
  79.             ' error occured
  80.             WriteFileData = L_FILEERROR_ERRORMESSAGE
  81.             Call SA_TraceOut(SA_GetScriptFileName(), "OpenTextFile(" & strFilePath & ") error: " & Hex(Err.Numer) & " " & Err.Description)
  82.             Err.Clear 
  83.             Exit Function
  84.         End If
  85.  
  86.         ' loop till EOF
  87.         While NOT objFile.AtEndofStream 
  88.             Response.Write( oEncoder.EncodeElement(objFile.ReadLine) & "<br>" )
  89.         Wend
  90.         
  91.         If Err.number <> 0 Then
  92.             ' error occured
  93.             WriteFileData = L_FILEERROR_ERRORMESSAGE
  94.             Call SA_TraceOut(SA_GetScriptFileName(), "File I/O Error reading file " & strFilePath & "  Error: " & Hex(Err.Numer) & " " & Err.Description)
  95.             Err.Clear 
  96.             Exit Function
  97.         End If
  98.         
  99.         'Clean up
  100.         Set objFile = Nothing
  101.         Set objFso  = Nothing
  102.         Set oEncoder = Nothing
  103.         ' Success, return <empty> string
  104.         WriteFileData = ""
  105.  
  106.     End function    
  107.  
  108.     '-------------------------------------------------------------------------
  109.     ' Function name:    ShowErrorMessageAndExit
  110.     ' Description:        Serves in displaying the message and terminating the Response
  111.     ' Input Variables:    strMessage  - the message to be displayed
  112.     ' Output Variables:    None
  113.     ' Returns:            None
  114.     'Displays the message and quits
  115.     '-------------------------------------------------------------------------
  116.     Sub ShowErrorMessageAndExit(strMessage)
  117.         On Error Resume Next
  118.         Err.Clear 
  119.  
  120.         Dim oEncoder
  121.         oEncoder = new CSAEncoder
  122.  
  123.         
  124.         ' display the message
  125.         Response.Write( oEncoder.EncodeElement(strMessage))
  126.  
  127.         Set oEncoder = Nothing
  128.  
  129.         ' terminate the response
  130.         Response.End 
  131.  
  132.     End Sub
  133. %>
  134.